package com.spider.admin.logs.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.spider.admin.conf.StructVar;
import com.spider.admin.utils.CommonUtil;
import jakarta.persistence.Id;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

@Getter
@Setter
@Data
@Accessors(chain = true)   // 链式赋值(连续set方法)

@AllArgsConstructor
@NoArgsConstructor
@ToString
@Document(indexName = StructVar.LOG_INDEX_NAME)
public class LogDocument implements Serializable {
    /**
     * 1.文档ID（系统自动生成，不需要处理）
     */
    @Id
    @Field(name = "id", type = FieldType.Text)
    private String id = CommonUtil.getUniqueKey();


    /**
     * 2.虚拟ID，用于计数
     */
    @JsonIgnore
    @Field(name = "vid", type = FieldType.Integer)
    private Integer vid = 1;
    /**
     * 3.请求服务域名
     */
    @Field(name = "requestServerName", type = FieldType.Text)
    private String requestServerName;
    /**
     * 4.请求服务地址
     */
    @Field(name = "requestUrl", type = FieldType.Text)
    private String requestUrl;


    /**
     * 5.请求Parmas参数
     */
    @Field(name = "reqParams", type = FieldType.Text)
    private String reqParams;

    /**
     * 6.请求体数据（2KB以内JSON）
     */
    @Field(name = "reqBody", type = FieldType.Text)
    private String reqBody;

    /**
     * 7.请求数据长度（含头）
     */
    @Field(name = "reqDataLength", type = FieldType.Long)
    private Long reqDataLength;

    /**
     * 8.响应数据长度
     */
    @Field(name = "resDataLength", type = FieldType.Long)
    private Long resDataLength;

    /**
     * 9.请求服务时间（到毫秒）
     */
    @Field(name = "requestTime", type = FieldType.Date_Range, format = DateFormat.date_time)
    private Date requestTime=new Date();

    private String reqDate;

    /**
     * 10.请求响应时长（毫秒）
     */
    @Field(name = "resTime", type = FieldType.Long)
    private Long resTime;


    /**
     * 11.后端消耗时长（毫秒）
     */
    @Field(name = "serverResTime", type = FieldType.Long)
    private Long serverResTime;

    /**
     * 12.客户端浏览器信息
     */
    @Field(name = "clientAgent", type = FieldType.Text)
    private String clientAgent;

    /**
     * 13.客户端IP地址
     */
    @Field(name = "clientIp", type = FieldType.Text)
    private String clientIp;

    /**
     * 14.处理服务器IP
     */
    @Field(name = "serverIp", type = FieldType.Text)
    private String serverIp;

    /**
     * 16.响应状态
     */
    @Field(name = "resStatus", type = FieldType.Text)
    private String resStatus;

    @Field(name = "optStatus", type = FieldType.Text)
    private String optStatus;

    @Field(name = "optReson", type = FieldType.Text)
    private String optReson;
    /**
     * 17.请求头
     */
    @Field(name = "reqHeaders", type = FieldType.Text)
    private String reqHeaders;

    /**
     * 18.响应头
     */
    @Field(name = "resHeaders", type = FieldType.Text)
    private String resHeaders;

    /**
     * 19.响应体(2KB以内JSON）
     */
    @Field(name = "resBody", type = FieldType.Text)
    private String resBody;

/**============================================================================================================================*/
    /**
     * 20.业务事件流水号
     */
    @Field(name = "bizEventId", type = FieldType.Text)
    private String bizEventId;

    /**
     * 20.业务事件流水号
     */
    @Field(name = "bizEventType", type = FieldType.Text)
    private String bizEventType;

    /**
     * 21.业务主数据类型
     */
    @Field(name = "mdTypeCode", type = FieldType.Text)
    private String mdTypeCode;

    /**
     * 22.业务主数据ID
     */
    @Field(name = "mdId", type = FieldType.Text)
    private String mdId;

    /**
     * 23.调用租户ID
     */
    @Field(name = "tenantId", type = FieldType.Text)
    private String tenantId;
    /**
     * 24.调用租户名称
     */
    @Field(name = "tenantName", type = FieldType.Text)
    private String tenantName;

    /**
     * 25.发布服务租户ID
     */
    @Field(name = "pubTenantId", type = FieldType.Text)
    private String pubTenantId;

    /**
     * 26.发布服务租户名称
     */
    @Field(name = "pubTenantName", type = FieldType.Text)
    private String pubTenantName;
    @Field(name = "appId", type = FieldType.Text)
    private String appId;
    @Field(name = "appName", type = FieldType.Text)
    private String appName;
    @Field(name = "serviceId", type = FieldType.Text)
    private String serviceId;
    @Field(name = "serviceName", type = FieldType.Text)
    private String serviceName;
    /**
     * 27.调用客户端ID
     */
    @Field(name = "callClientId", type = FieldType.Text)
    private String callClientId;

    /**
     * 28.调用客户端名称
     */
    @Field(name = "callClientName", type = FieldType.Text)
    private String callClientName;

    /**
     * 29.调用服务真实地址（去处url路径参数后地址）
     */
    @Field(name = "callServiceRealUrl", type = FieldType.Text)
    private String callServiceRealUrl;


}
